/**
 * 
 */
package com.shiplanet.entity;

import java.util.Date;
import java.util.Set;
import java.util.TreeSet;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

@Entity
@Table(name = "POST")
public class Post {

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "P_ID")
	private Integer id;

	@Column(name = "IS_APPROVED")
	private boolean isApproved;

	@Column(name = "CREATE_TIME")
	private Date createTime;

	@Column(name = "VIEW_CNT")
	private long viewCounter;

	@Column(name = "TITLE")
	private String title;

	@Column(name = "IS_FEATURED")
	private boolean isFeatured;

	@Column(name = "IS_TOPPED")
	private boolean isTopped;

	@Column(name = "EQUP_NAME")
	private String equipmentName;

	@Column(name = "EQUP_ITEM_NO")
	private String equipmentItemNumber;

	@Column(name = "EQUP_MANU")
	private String equipmentManufacturer;

	@Column(name = "EQUP_LOC")
	private String equipmentLocation;

	@Column(name = "EQUP_YEAR")
	private Date equipmentYear;

	@Column(name = "EQUP_DESC")
	private String equipmentDescription;

	@Column(name = "EQUP_ISSOLD")
	private boolean equipmentIsSold;

	@Column(name = "INTER_MEMO")
	private String interMemo;

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "C_ID")
	private Category category;

	@OneToMany(cascade = CascadeType.ALL, mappedBy = "post", fetch = FetchType.EAGER, orphanRemoval = true)
	@OrderBy(value = "url ASC")
	private Set<Photo> photos = new TreeSet<Photo>();

	// private User user;
	//
	// public User getUser() {
	// return user;
	// }
	//
	//

	public Integer getId() {
		return id;
	}

	public Set<Photo> getPhotos() {
		return photos;
	}

	public boolean isApproved() {
		return isApproved;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public long getViewCounter() {
		return viewCounter;
	}

	public String getTitle() {
		return title;
	}

	public boolean isFeatured() {
		return isFeatured;
	}

	public boolean isTopped() {
		return isTopped;
	}

	public String getEquipmentName() {
		return equipmentName;
	}

	public String getEquipmentItemNumber() {
		return equipmentItemNumber;
	}

	public String getEquipmentManufacturer() {
		return equipmentManufacturer;
	}

	public String getEquipmentLocation() {
		return equipmentLocation;
	}

	public Date getEquipmentYear() {
		return equipmentYear;
	}

	public void setEquipmentYear(Date equipmentYear) {
		this.equipmentYear = equipmentYear;
	}

	public String getEquipmentDescription() {
		return equipmentDescription;
	}

	public boolean isEquipmentIsSold() {
		return equipmentIsSold;
	}

	public String getInterMemo() {
		return interMemo;
	}

	public Category getCategory() {
		return category;
	}

	@SuppressWarnings("unused")
	private void setId(Integer id) {
		this.id = id;
	}

	// public void setUser(User user) {
	// this.user = user;
	// }

	public void setCategory(Category category) {
		this.category = category;
	}

	public void setApproved(boolean isApproved) {
		this.isApproved = isApproved;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public void setViewCounter(long viewCounter) {
		this.viewCounter = viewCounter;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public void setFeatured(boolean isFeatured) {
		this.isFeatured = isFeatured;
	}

	public void setTopped(boolean isTopped) {
		this.isTopped = isTopped;
	}

	public void setEquipmentDescription(String equipmentDescription) {
		this.equipmentDescription = equipmentDescription;
	}

	public void setEquipmentLocation(String equipmentLocation) {
		this.equipmentLocation = equipmentLocation;
	}

	public void setEquipmentManufacturer(String equipmentManufacturer) {
		this.equipmentManufacturer = equipmentManufacturer;
	}

	public void setEquipmentName(String equipmentName) {
		this.equipmentName = equipmentName;
	}

	public void setEquipmentItemNumber(String equipmentItemNumber) {
		this.equipmentItemNumber = equipmentItemNumber;
	}

	public void setEquipmentIsSold(boolean equipmentIsSold) {
		this.equipmentIsSold = equipmentIsSold;
	}

	public void setInterMemo(String interMemo) {
		this.interMemo = interMemo;
	}

	public void setPhotos(Set<Photo> photos) {
		this.photos = photos;
	}

	public boolean addPhoto(Photo photo) {
		boolean isAdded = getPhotos().add(photo);
		if (isAdded) {
			photo.setPost(this);
			return true;
		}
		return false;
	}

}